import CodeView from '../../../shared/components/CodeView';
import DisplayColumn from '../../../shared/components/DisplayColumn';
import DisplayGrid from '../../../shared/components/DisplayGrid';
import Blockquote from '../../../shared/components/Blockquote';
import RequiredLabelExample from '../../../shared/components/RequiredLabelExample';
import { getDisplayElementById, getDemoStylesById } from '../../shared/helpers';
import { MobileNotice, MobileBlurb } from '../../shared/doc-text';
import * as Base from './base/example';
import StylingHooksTable from '../../../shared/components/StylingHooksTable';

<div className="doc lead">
  A select list that can have a single entry checked at any one time.
</div>

<CodeView exampleOnly>{getDisplayElementById(Base.default)}</CodeView>

## About Radio Group

Radio buttons are shown in a group of two or more. The user can only select one radio button at a time. You should use the same `name` attribute on all radio buttons in the group. This ensures that if there is more than one group in the form, each one stays associated with its own group.

The ability to style radio buttons with CSS varies across browsers. To ensure that radio buttons look the same everywhere, we use a custom DOM. Pay close attention to the markup, because all elements must exist for the styles to work.

### Accessibility

Groups of radio buttons should be marked up using the fieldset and legend element. This helps someone using assistive technology to understand the question they're answering with the group of radio buttons. The fieldset is placed around the whole group and the legend contains the question.

Custom radio buttons are created by applying the `.slds-radio` class to a `<label>` element. To remain accessible to all user agents, place an `<input>` with `type="radio"` inside the `<label>` element. The `<input>` is then visually hidden, and the styling is placed on a span with the `.slds-radio_faux` class. The styling of the span changes based on whether the radio button is selected or focused by using a pseudo-element. A second span with `.slds-form-element__label` contains the label text.

When a radio group is required, the `<fieldset>` should receive the class `.slds-is-required`. The `<legend>` should then get `<abbr class="required" title="required" aria-hidden="true">*</abbr>` added to the DOM for visual indication that the radio group is required.

Example:
<RequiredLabelExample/>

When disabling a radio button, either the entire group must be disabled or if only some radio buttons are disabled, then the checked radio button cannot be disabled.

### Mobile

<MobileBlurb patternSpecificText="radio groups will have an increased size to accommodate tapping with a finger instead of the more precise mouse cursor" />

<CodeView frameOnly frameTitle="Example mobile styles for radio groups">{getDisplayElementById(Base.default)}</CodeView>

## Base

<CodeView>{getDisplayElementById(Base.default)}</CodeView>

## States

### Disabled

<CodeView>{getDisplayElementById(Base.states, 'disabled')}</CodeView>

### Checked and Disabled

<CodeView>
  {getDisplayElementById(Base.states, 'checked-and-disabled')}
</CodeView>

### Required

<CodeView>{getDisplayElementById(Base.states, 'required')}</CodeView>

### Error

<CodeView>{getDisplayElementById(Base.states, 'error')}</CodeView>

### Required with Help Text Icon

<CodeView>{getDisplayElementById(Base.states, 'required-help-text-icon')}</CodeView>

### Required with Help Text Icon and Tooltip

<CodeView demoStyles={getDemoStylesById(Base.states, 'required-help-text-icon-tooltip')}>
  {getDisplayElementById(Base.states, 'required-help-text-icon-tooltip')}
</CodeView>

### Right to Left

<CodeView>{getDisplayElementById(Base.states, 'rtl')}</CodeView>

### Right to Left Required with Help Text Icon

<CodeView>{getDisplayElementById(Base.states, 'rtl-required-help-text-icon')}</CodeView>

## Styling Hooks Overview

<StylingHooksTable name="radio-group" type="component" />
